import { quest } from "../../utils/http";

// pages/detail/detail.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    detail: [],
    page: "",
    image:
      "https://ts1.cn.mm.bing.net/th/id/R-C.3c631678349a4f39d2ab5dd87eb4a482?rik=42SNEyQ4hUOeIQ&riu=http%3a%2f%2fimg1.gtimg.com%2fkid%2fpics%2fhv1%2f154%2f125%2f1879%2f122214004.jpg&ehk=CLHgcOrj9sSvS9Vm4qiTjat4%2bgfAmObfYnxUhnEH%2fA8%3d&risl=&pid=ImgRaw&r=0",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    let detail = JSON.parse(e.detail);
    console.log(e.page);
    this.setData({
      detail,
      page: e.page,
    });
  },
  goBack() {
    wx.navigateBack({
      delta: 0,
    });
  },
  async addOrder(e) {
    let user = await quest({
      url: "user/ByToken",
    });
    if (user.data.phone == "") {
      wx.showModal({
        cancelText: "取消",
        confirmText: "确定",
        content: "请先添加手机号",
        editable: false,
        showCancel: true,
        title: "提示",
        success: () => {
          wx.switchTab({
            url: "/pages/me/me",
          });
        },
      });
      return;
    }
    let data = await quest({
      url: "express/addOrder",
      method: "post",
      data: {
        id: this.data.detail.id,
      },
    });
    if (data.code == 200) {
      this.setData({ detail: data.data });
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  async finishOrder() {
    let data = await quest({
      url: "express/update",
      method: "post",
      data: {
        id: this.data.detail.id,
        status: 1,
      },
    });
    if (data.code == 200) {
      wx.showModal({
        title: "提示",
        content: "收货成功",
        success(res) {
          if (res.confirm) {
            wx.navigateBack;
          } else if (res.cancel) {
            console.log("用户点击取消");
          }
        },
      });
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
